<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : uipage.core.php   FILE_PATH : \\classes\core\uipage.core.php
 * ....页面显示初始化类
 * 页面操作类需要继承此类
 * 本类中定义了页面所需的元素
 * 
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Tue Aug 07 12:52:43 CST 2007
 */

class UIPage extends BaseInitialize{

	/**
	 * 模板子路径
	 *
	 * @var string
	 */
	var $_subtemplates = "";
	/**
	 * SMARTY对象
	 *
	 * @var obj
	 */
	var $_objsmarty;

	/**
	 * 初始化UI部分
	 *
	 */
	function _uiinitialize(){
		/**
		 * 设置模版路径
		 */
		$this->_settemplates();
	}

	/**
	 * 设置模板显示信息
	 *
	 */
	function _settemplates(){
		/**
 		 * 装载Smarty.class.php,并实例化对象
 		 */
		include_once('Smarty.class.php');
		define("Templates",BasePath . "/templates");
		$this->_objsmarty = new Smarty();                                           //建立smarty实例对象$smarty
		$this->_objsmarty->debugging = false;
		
		$this->_objsmarty->template_dir   = Templates . "/" . $this->_configinfo['websit']['templatesname'] ;                    //设置模板目录
//		$this->_objsmarty->compile_dir    = Templates . "/" . $this->_configinfo['websit']['templatesname'] . "/templates_c";    //设置编译目录
		$this->_objsmarty->compile_dir    = Templates . "/templates_c";
		
		$this->_objsmarty->cache_charset = strtoupper($this->_configinfo['websit']['ncharset']);	//设置缓存文件编码
		$this->_objsmarty->cache_dir      = BasePath . "/cache";                     //设置缓存目录
		$this->_objsmarty->cache_lifetime = $this->_systeminfo['global']['cachetime'];                           //设置缓存时间
		if ($this->_systeminfo['global']['ifcache'] == "true"){
			$this->_objsmarty->caching = true;
		}else{
			$this->_objsmarty->caching = false;                   //这里是调试时设为false,发布时请使用true
		}

		$this->_objsmarty->left_delimiter = $this->_systeminfo['template']['left_delimiter'];
		$this->_objsmarty->right_delimiter= $this->_systeminfo['template']['right_delimiter'];

		/**
 		 * 在这里将部分系统主要变量生成到摸板上，以便于调用。
		 */
		$this->_objsmarty->assign("template_dir",  $this->_configinfo['websit']['site_url'] . "/templates/" . $this->_configinfo['websit']['templatesname']); //摸板路径
		$this->_objsmarty->assign("templatepath",   "/templates/" . $this->_configinfo['websit']['templatesname'] . $this->_subtemplates); //摸板相对路径
		$this->_objsmarty->assign("Site_Url",      $this->_configinfo['websit']['site_url']);       //主站URL
		$this->_objsmarty->assign("Site_LOGO",      $this->_configinfo['websit']['logo_url']);       //主站URL
		$this->_objsmarty->assign("NCharset",      $this->_configinfo['websit']['ncharset']);       //页面编码
		$this->_objsmarty->assign("Meta_keyword",  $this->_configinfo['websit']['meta_keyword']);   //META内容
		$this->_objsmarty->assign("Meta_desc",     $this->_configinfo['websit']['meta_desc']);      //META内容
		$this->_objsmarty->assign("RootDocumentAdmin",    BasePath . "/" . $this->_configinfo['websit']['systemadmin']);  //后台管理路径
	}

	/**
	 * 抛出变量到页面
	 *
	 * @param string $varstring
	 * @param var $var
	 */
	function output($varstring,$var=""){
		if ($var == ""){
			$this->_objsmarty->assign($varstring);
		}else{
			$this->_objsmarty->assign($varstring,Common::stripslashes_array($var));
		}
	}

	/**
	 * 清空编译后的数据
	 * @param string $templatesname
	 */
	function clearCompiledTpl($templatesname){
		$templatesfile  = $this->_objsmarty->template_dir."/".$templatesname.".html";
		$this->_objsmarty->clear_compiled_tpl($templatesfile);
	}
	/**
	 * 显示模板内容
	 *
	 * @param string $pagename
	 */
	function showpage($pagename){
		//版权信息开关
		if ($this->check_powerby == true){
			$title = '- Powered by ShopNC';
		}
		$this->_objsmarty->assign("HtmlTitle",     $this->_configinfo['websit']['site_title'].$title);     //TITLE内容，包含版权信息，避免中途被修改
		//输出版本号
		$this->_objsmarty->assign("SystemVersion",  $this->_systeminfo['version']['revision']);
		$this->_objsmarty->display($pagename . ".html");
	}
	/**
	 * 取模板内容
	 *
	 * @param string $pagename
	 */
	function fetchpage($pagename){
		//版权信息开关
		if ($this->check_powerby == true){
			$title = '- Powered by ShopNC';
		}
		$this->_objsmarty->assign("HtmlTitle",     $this->_configinfo['websit']['site_title'].$title);     //TITLE内容，包含版权信息，避免中途被修改
		return $this->_objsmarty->fetch($pagename . ".html");
	}
	/**
	 * 清除所有已经存在的页面变量
	 *
	 * @param string $pagename
	 */
	function clearAllAssign(){
		return $this->_objsmarty->clear_all_assign();
	}
	/**
	 * 清除指定页面变量
	 *
	 * @param string $pagename
	 */
	function clearAssign($param){
		return $this->_objsmarty->clear_assign($param);
	}
	/**
	 * 设置模板子路径
	 *
	 * @param string $templatesname
	 */
	function setsubtemplates($templatesname){
		$this->_subtemplates = $templatesname;  //模版子路径

		if($this->_subtemplates != ""){
			$this->_subtemplates = "/" . $this->_subtemplates;
		}
		$this->_objsmarty->template_dir   = Templates . "/" . $this->_configinfo['websit']['templatesname'] . $this->_subtemplates;                    //设置模板目录
//		$this->_objsmarty->compile_dir    = Templates . "/" . $this->_configinfo['websit']['templatesname'] . $this->_subtemplates . "/templates_c";   //设置编译目录
		$this->_objsmarty->compile_dir    = Templates . "/templates_c";
		$this->_objsmarty->assign("templates_subpath",      "/templates/" . $this->_configinfo['websit']['templatesname'] . $this->_subtemplates);     //抛出摸班子路径
	}

	/**
	 * 自定义店铺模板目录
	 *
	 * @param string $templatesname
	 */
//	function setStoreTemplates($templatesname){
//		$this->_objsmarty->template_dir   = Templates . "/" . $this->_configinfo['websit']['storetemplatename'] . "/" . $templatesname;                    //设置模板目录
//		$this->_objsmarty->compile_dir    = Templates . "/" . $this->_configinfo['websit']['storetemplatename'] . "/" . $templatesname . "/templates_c";     //设置编译目录
//	}
	
	/**
	 * 根据应用标识，重新定义模板目录的路径
	 * @author workflow Develop Team     
	 * @param  $app_path 应用标识,$temp_path 模板文件夹
	 * @return 
	 */
	function _set_app_templates($app_path,$temp_path){
		if ($app_path != ''){
			if ($temp_path != ''){
				$this->_objsmarty->template_dir   = BasePath . "/app/" . $app_path .'/templates/'.$temp_path;
//				$this->_objsmarty->compile_dir    = BasePath . "/app/" . $app_path .'/templates/'.$temp_path.'/templates_c';
				$this->_objsmarty->compile_dir    = BasePath . "/app/" . $app_path .'/templates/templates_c';
			}else {
				$this->_objsmarty->template_dir   = BasePath . "/app/" . $app_path .'/templates';
				$this->_objsmarty->compile_dir    = BasePath . "/app/" . $app_path .'/templates/templates_c';
			}
			is_writable($this->_objsmarty->template_dir)?'':die('You app file ('. $this->_objsmarty->template_dir .') is not write!Please check the permissions');
			is_writable($this->_objsmarty->compile_dir)?'':die('You app file ('. $this->_objsmarty->compile_dir .') is not write!Please check the permissions');
			
			//增加app classes路径
			$this->_systeminfo['global']['includepath'] .= ','.'app/'.$app_path.'/classes/application';
			$this->_setincludepage();
			
			//对模板路径重新进行赋值
			$this->_objsmarty->assign("template_dir",  $this->_configinfo['websit']['site_url'] . "/app/". $app_path ."/templates");
		}else {
			return false;
		}
	}
	
}
?>